const Router = require('koa-router')
const { DefaultController } = require('../../controllers')
const { HttpDataResolve, Validator } = require('../../common')
const { Auth, SP_ADMIN, ADMIN } = require('../../middleware/auth')
const res = new HttpDataResolve()

const router = new Router({
  prefix: '/api/v1/default'
})

router.post('/image', new Auth().m, async (ctx, next) => {
  const path = await DefaultController.image(ctx, next)

  ctx.response.status = 200
  ctx.body = res.json({
    path
  })
})

// 点赞
router.post('/like', new Auth().m, async ctx => {
  const data = new Validator(ctx, {
    target_id: 'number',
    type: 'include:comment,article'
  })

  const result = await DefaultController.like(data, ctx.auth);

  ctx.response.status = 200;
  ctx.body = res.json({
    count: result
  })
})

module.exports = router
